package com.javaex.book.pojo;

import java.util.Date;
import java.util.Objects;

/**
 * 用户信息类，对应数据库中的user表
 *
 * @author 黄星琦
 * @Date 2022年1月15日
 */
public class User {
	
	private Integer id;
	
	/** 用户名 */
	private String username;
	
	/** 年龄 */
	private Integer age;
	
	/** 性别。0男，1女 */
	private Integer gender;
	
	/** 密码 */
	private String password;
	
	/** 邮箱 */
	private String email;
	
	/** 用户注册时间 */
	private Date createTime;
	
	public User() {}

	public User(String username, int age, int gender, String password, String email) {
		this.username = username;
		this.age = age;
		this.gender = gender;
		this.password = password;
		this.email = email;
	}

	public int getId() {
		return id;
	}
	
	public void setId(Integer id) {
		this.id = id;
	}
	
	public String getUsername() {
		return username;
	}
	
	public void setUsername(String username) {
		this.username = username;
	}
	
	public int getAge() {
		return age;
	}
	
	public void setAge(Integer age) {
		this.age = age;
	}
	
	public int getGender() {
		return gender;
	}
	
	public void setGender(Integer gender) {
		this.gender = gender;
	}
	
	public String getPassword() {
		return password;
	}
	
	public void setPassword(String password) {
		this.password = password;
	}
	
	public String getEmail() {
		return email;
	}
	
	public void setEmail(String email) {
		this.email = email;
	}
	
	public Date getCreateTime() {
		return createTime;
	}
	
	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}

	@Override
	public String toString() {
		return "User {id=" + id + ", username=" + username + ", age=" + age + ", gender=" + gender + ", password=" + password + ", email=" + email
				+ ", createTime=" + createTime + "}";
	}

	@Override
	public int hashCode() {
		return Objects.hash(age, email, gender, password, username);
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj) {
			return true;
		}
		if (obj == null) {
			return false;
		}
		if (getClass() != obj.getClass()) {
			return false;
		}
		User other = (User) obj;
		if (other.getPassword() == null || other.getPassword().isEmpty() || this.password == null || this.password.isEmpty()) {
			return Objects.equals(age, other.age) && Objects.equals(email, other.email) && Objects.equals(gender, other.gender)
					&& Objects.equals(username, other.username);
		}
		return Objects.equals(age, other.age) && Objects.equals(email, other.email) && Objects.equals(gender, other.gender)
				&& Objects.equals(password, other.password) && Objects.equals(username, other.username);
	}
}
